Ext.define('StaffServer.controller.MenuController', {
	extend : 'Ext.app.Controller',
	
	refs : [{
		ref : 'west',
		selector : 'west'
	}, {
		ref : 'center',
		selector : 'center'
	}],

	//初始化执行语句
	init : function() {
		Ext.QuickTips.init();
		//遮罩层效果
		Ext.EventManager.onDocumentReady(function() {
			setTimeout(function() {
				Ext.get('loading').remove();
				Ext.get('loading-mask').fadeOut({
					remove : true
				});
			}, 100);
		});

		//控制事件
		this.control({
			'west' : {
				itemclick : this.onMenuTreeItemclick
			}
		});	},

	//菜单树点击事件
	onMenuTreeItemclick : function(view, node, item, index, e) {
		var me = this;
		var url = node.get('url');
		if (node.get('leaf')) {
			var mainTabPanel = this.getCenter();
			var tab = mainTabPanel.getComponent(node.get('id'));
			if (!tab) {
				var newTab = {
					title : node.get('text'),
					id : node.get('id'),
					closable : true
				};
				var controller = me.application.loadController(url);
				tab = mainTabPanel.add(Ext.create(controller.tabView,newTab));
			}
			mainTabPanel.setActiveTab(tab);
		}
	}
});